home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 089a.dms / 089a.adf / TEXTS / CHAPTERS_21-30 / Chapter25.txt < prev    next >
Text File  |  1992-03-06  |  8KB  |  246 lines

  1.                      The Absolute Beginners Guide To Amos
  2.                     -------------------------------------
  3.                              Chapter Twenty Five
  4.                             ----------------------
  5. Here are a few random bits and pieces that need mentioning before we venture
  6. on in to more advanced territory.
  7.  
  8. I have covered the IF THEN statement a lot but only mentioned in passing the
  9. IF-END IF structure. Take a look at the two examples below.
  10.  
  11. REM IF THEN example
  12. '------------------
  13. IF A=1 THEN PRINT" A is equal to one":CLEAR KEY: WAIT KEY: CLS 0: STOP
  14.  
  15.  
  16. REM IF END IF example
  17. '-------------------
  18. IF A=1
  19. PRINT" A is equal to one"
  20. CLEAR KEY: WAIT KEY
  21. CLS 0
  22. STOP
  23. END IF
  24.  
  25. As you may imagine END IF can be useful if you have a lot of things to do
  26. between a IF and a THEN statement which you would either have to fit on to
  27. one line or call a subroutine or procedure.  What IF-END IF comes down to is
  28. that the lines of code between the IF and the END IF will ONLY be executed
  29. If the IF condition is true. If the IF part is false then Amos will look
  30. for the END IF instruction and jump to the next line after that.
  31.  
  32. EXIT IF
  33. ------
  34. Another benefit of IF-END IF is the EXIT IF structure. 
  35. This can EXIT the IF-END IF structure at any stage, for example:
  36.  
  37. EXIT IF a>1
  38.  
  39. That's enough of that we have learnt quite a few control structures
  40. recently and I don't want to bog you down.
  41.  
  42.  
  43. DIRECT
  44. ------
  45. I have used the EDIT instruction quite a lot in the Example programs but not
  46. the DIRECT instruction, which is the same as pressing escape from the editor.
  47. It's pretty useless but now you know.
  48.  
  49.  
  50. INVERSE
  51. -------
  52. INVERSE is a very simple instruction indeed.  What it does is swap the 
  53. colour of your text with the background colour. For example, if you had a 
  54. black screen and printed some white text on it INVERSE ON would make the 
  55. text in PAPER white and PEN black:
  56.  
  57. INVERSE ON
  58. PRINT" INVERSED"
  59. INVERSE OFF
  60. PRINT"NORMAL"
  61.  
  62. Don't forget everything you PRINT will come out INVERSED until you issue
  63. the INVERSE OFF instruction, similar to the UNDER ON/OFF instruction in 
  64. usage.
  65.  
  66.  
  67. HOME
  68. ----
  69. Using the instruction HOME is the same as using LOCATE 0,0: It sets the text
  70.  cursor to the top left hand corner of the screen.
  71.  
  72.  
  73. CLINE
  74. -----
  75. CLINE is a very useful instruction. It CLears the LINE on which the text
  76. cursor is currently positioned on. An optional parameter can be used to tell
  77. CLINE how much of the line is to be cleared:
  78.  
  79. CLINE        (Clear the whole line)
  80.  
  81. or 
  82.  
  83. CLINE 12    (Clear 12 characters of the line)
  84.  
  85. The text cursor position is unaffected by CLINE.
  86.  
  87.  
  88. TIMER and RANDOMIZE
  89. -------------------
  90. TIMER is a system variable that is incremented every 50th of a second. 
  91. TIMER starts as soon as you switch on your Amiga, even before you load Amos!
  92. It has it's uses, but is most used in conjunction with the RANDOMIZE 
  93. instruction. The RND function is what is known as a pseudo random number
  94. generator. The numbers given by RND are random enough for most uses but in 
  95. something like a card game it's limitations would be exposed. 
  96. RND eventually loops and reproduces a set sequence of numbers. 
  97. To get around this RND can be given a new seed to gather it's sequence from.
  98. This is where TIMER comes in handy as TIMER is a continually changing number,
  99. so to ensure a good RND sequence we just do this:
  100.  
  101. RANDOMIZE TIMER
  102.  
  103.  
  104.  
  105. PARENT
  106. ------
  107. PARENT is a instruction that is useful if you are wading through a disk full
  108. of drawers. Say for instance you wanted to look inside your pictures drawer:
  109.  
  110. DIR$="PICTURES/"
  111. DIR 
  112.  
  113. But now you want to return to the root directory, all you do is:
  114.  
  115. PARENT
  116.  
  117. In that example we could have just issued a DIR$="DF0:" or whatever to get
  118. the same effect but where PARENT is more useful is if you are in a drawer of
  119. a drawer and just want to return to the first drawer: 
  120.  
  121. DIR$="PICTURES/HAMPICS/"
  122. DIR
  123. PARENT
  124.  
  125. Would leave you inside the pictures drawer and not the hampics drawer.
  126. By the way the DIR instruction simply prints a DIRectory listing of the 
  127. contents of the current directory to the screen.
  128.  
  129.  
  130. RUN
  131. ---
  132. A quick word about the RUN instruction. This is useful if you want to chain 
  133. a lot of programs together. Here is an example:
  134.  
  135. RUN "LEVEL1.Amos"
  136.  
  137. And when LEVEL1 has been completed you RUN "LEVEL2.Amos" from there. The RUN
  138. instruction can only be used with Amos compiled code and not executable 
  139. compiled code so is of limited use.
  140. ============================================================================
  141.  
  142. To keep you interested I have knocked up a simple program that you can get 
  143. to work on and practice some of the commands you have recently learnt. 
  144. I have commented every part of the listing here and in Example25.Amos.
  145. You shouldn't have too much trouble understanding it. If you get stuck
  146. anywhere look up the command(s) in your note book, failing that look them
  147. up in the index and re-read the relevant chapters. I am not going to suggest
  148. what you should do with it, just experiment and see how far you can get.
  149. Have fun.
  150.  
  151.  
  152. 'The beginnings of a ship thingy. It could be anything you want! 
  153.  
  154. Rem Hide the mouse pointer and unpack the picture I have stored in bank 10 
  155. Rem Set double buffer on to cut down on flicker.
  156. '------------------------------------------------------------------------- 
  157. Hide 
  158. Unpack 10 To 0
  159. Double Buffer 
  160.  
  161.  
  162. Rem Set the following variables to be used inside and outside
  163. Rem of procedures. 
  164. '------------------------------------------------------------- 
  165. Global XOFF,YOFF
  166.  
  167.  
  168. Rem Set up the variables: 
  169. Rem XOFF is the x offset of the screen display 
  170. Rem YOFF is Y offset 
  171. Rem AC is the x position of the ship 
  172. Rem DWN is the y position of the ship 
  173. Rem IMAGE is the bob bank image number being used for the ship
  174. Rem Image 2 is the ship facing right, Image 3 facing left 
  175. Rem X means horizontal,left<>right,  Y means vertical.    
  176. '--------------------------------------------------------------
  177. XOFF=0 : YOFF=0 : AC=100 : DWN=150 : IMAGE=2
  178.  
  179.  
  180. Rem The main loop
  181. '----------------
  182. REM Start the DO-LOOP structure.
  183. '--------------------------------
  184. Do 
  185.  
  186. Rem place Bob 1 at the coordinates ac,dwn (across,down) Image will 
  187. Rem be set to the correct direction. 
  188. '----------------------------------------------------------------------
  189. Bob 1,AC,DWN,IMAGE
  190.  
  191. Rem Now deal with the joystick. We are only interested in left and right 
  192. Rem movement.  
  193. Rem If pressed to right then we INCrease xoff by one, update the bobs 
  194. Rem position by INCreasing AC then make sure IMAGE is equal to 2 pointing 
  195. Rem right.
  196. '------------------------------------------------------------------------ 
  197. If Jright(1) Then Inc XOFF : Inc AC : IMAGE=2
  198.  
  199. Rem Joystick left is virtually the same except using DECrease and image 3
  200. '---------------------------------------------------------------------------
  201. If Jleft(1) Then Dec XOFF : Dec AC : IMAGE=3
  202.  
  203. Rem The following lines make sure the ship stays inside the screen. 
  204. Rem If AC=0 then the ship has reached the left edge of the screen to stop
  205. Rem it going off the edge we make sure AC stays at a minimum of 0. 
  206. Rem The right is 896 we do the same. It's 896 because the loaded picture is 
  207. Rem that wide, I created the picture in DPAINT and using the screen size
  208. Rem settings set the width to 896 this.
  209. '---------------------------------------------------------------------------
  210. If AC<0 Then AC=0
  211. If AC>896 Then AC=896
  212.  
  213. Rem call the _UPD procedure which scrolls the screen 
  214. '---------------------------------------------------
  215. _UPD
  216.  
  217. Rem Wait Vbl slows things down and keeps it smooth. 
  218. Rem Try the game without it and see what you think.
  219. '----------------------------------------------------
  220. Wait Vbl 
  221.  
  222. Rem The end of the main loop, jumps back to the DO command.
  223. '----------------------------------------------------------
  224. Loop 
  225.  
  226.  
  227. Procedure _UPD
  228.  
  229. Rem This stops the screen scrolling too far like in the AC bit above 
  230. '------------------------------------------------------------------- 
  231.  If XOFF<0 Then XOFF=0
  232.  If XOFF>620 : XOFF=620 : End If 
  233.  If YOFF<0 Then YOFF=0
  234.  If YOFF>200 : YOFF=0 : End If 
  235.  
  236. Rem This is what scrolls the background,   
  237. '----------------------------------------- 
  238. Screen Offset 0,XOFF,YOFF
  239.  
  240. End Proc
  241.  
  242.  
  243.  
  244.                               End of Chapter 25
  245.                               ^^^^^^^^^^^^^^^^^
  246.